1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.WidgetClass; 26 27 private import glib.Bytes; 28 private import glib.Str; 29 private import glib.VariantType; 30 private import glib.c.functions; 31 private import gtk.BuilderScopeIF; 32 private import gtk.Shortcut; 33 private import gtk.c.functions; 34 public import gtk.c.types; 35 36 37 /** */ 38 public class WidgetClass 39 { 40 /** the main Gtk struct */ 41 protected GtkWidgetClass* gtkWidgetClass; 42 protected bool ownedRef; 43 44 /** Get the main Gtk struct */ 45 public GtkWidgetClass* getWidgetClassStruct(bool transferOwnership = false) 46 { 47 if (transferOwnership) 48 ownedRef = false; 49 return gtkWidgetClass; 50 } 51 52 /** the main Gtk struct as a void* */ 53 protected void* getStruct() 54 { 55 return cast(void*)gtkWidgetClass; 56 } 57 58 /** 59 * Sets our main struct and passes it to the parent class. 60 */ 61 public this (GtkWidgetClass* gtkWidgetClass, bool ownedRef = false) 62 { 63 this.gtkWidgetClass = gtkWidgetClass; 64 this.ownedRef = ownedRef; 65 } 66 67 68 /** 69 * Installs a shortcut in @widget_class. 70 * 71 * Every instance created for @widget_class or its subclasses will 72 * inherit this shortcut and trigger it. 73 * 74 * Shortcuts added this way will be triggered in the %GTK_PHASE_BUBBLE 75 * phase, which means they may also trigger if child widgets have focus. 76 * 77 * This function must only be used in class initialization functions 78 * otherwise it is not guaranteed that the shortcut will be installed. 79 * 80 * Params: 81 * shortcut = the `GtkShortcut` to add 82 */ 83 public void addShortcut(Shortcut shortcut) 84 { 85 gtk_widget_class_add_shortcut(gtkWidgetClass, (shortcut is null) ? null : shortcut.getShortcutStruct()); 86 } 87 88 /** 89 * Declares a @callback_symbol to handle @callback_name from 90 * the template XML defined for @widget_type. 91 * 92 * This function is not supported after [method@Gtk.WidgetClass.set_template_scope] 93 * has been used on @widget_class. See [method@Gtk.BuilderCScope.add_callback_symbol]. 94 * 95 * Note that this must be called from a composite widget classes 96 * class initializer after calling [method@Gtk.WidgetClass.set_template]. 97 * 98 * Params: 99 * callbackName = The name of the callback as expected in the template XML 100 * callbackSymbol = The callback symbol 101 */ 102 public void bindTemplateCallbackFull(string callbackName, GCallback callbackSymbol) 103 { 104 gtk_widget_class_bind_template_callback_full(gtkWidgetClass, Str.toStringz(callbackName), callbackSymbol); 105 } 106 107 /** 108 * Automatically assign an object declared in the class template XML to 109 * be set to a location on a freshly built instance’s private data, or 110 * alternatively accessible via [method@Gtk.Widget.get_template_child]. 111 * 112 * The struct can point either into the public instance, then you should 113 * use `G_STRUCT_OFFSET(WidgetType, member)` for @struct_offset, or in the 114 * private struct, then you should use `G_PRIVATE_OFFSET(WidgetType, member)`. 115 * 116 * An explicit strong reference will be held automatically for the duration 117 * of your instance’s life cycle, it will be released automatically when 118 * `GObjectClass.dispose()` runs on your instance and if a @struct_offset 119 * that is `!= 0` is specified, then the automatic location in your instance 120 * public or private data will be set to %NULL. You can however access an 121 * automated child pointer the first time your classes `GObjectClass.dispose()` 122 * runs, or alternatively in [signal@Gtk.Widget::destroy]. 123 * 124 * If @internal_child is specified, [vfunc@Gtk.Buildable.get_internal_child] 125 * will be automatically implemented by the `GtkWidget` class so there is no 126 * need to implement it manually. 127 * 128 * The wrapper macros [func@Gtk.widget_class_bind_template_child], 129 * [func@Gtk.widget_class_bind_template_child_internal], 130 * [func@Gtk.widget_class_bind_template_child_private] and 131 * [func@Gtk.widget_class_bind_template_child_internal_private] 132 * might be more convenient to use. 133 * 134 * Note that this must be called from a composite widget classes class 135 * initializer after calling [method@Gtk.WidgetClass.set_template]. 136 * 137 * Params: 138 * name = The “id” of the child defined in the template XML 139 * internalChild = Whether the child should be accessible as an “internal-child” 140 * when this class is used in GtkBuilder XML 141 * structOffset = The structure offset into the composite widget’s instance 142 * public or private structure where the automated child pointer should be set, 143 * or 0 to not assign the pointer. 144 */ 145 public void bindTemplateChildFull(string name, bool internalChild, ptrdiff_t structOffset) 146 { 147 gtk_widget_class_bind_template_child_full(gtkWidgetClass, Str.toStringz(name), internalChild, structOffset); 148 } 149 150 /** 151 * Retrieves the accessible role used by the given `GtkWidget` class. 152 * 153 * Different accessible roles have different states, and are rendered 154 * differently by assistive technologies. 155 * 156 * See also: [method@Gtk.Accessible.get_accessible_role]. 157 * 158 * Returns: the accessible role for the widget class 159 */ 160 public GtkAccessibleRole getAccessibleRole() 161 { 162 return gtk_widget_class_get_accessible_role(gtkWidgetClass); 163 } 164 165 /** 166 * Retrieves the signal id for the activation signal. 167 * 168 * the activation signal is set using 169 * [method@Gtk.WidgetClass.set_activate_signal]. 170 * 171 * Returns: a signal id, or 0 if the widget class does not 172 * specify an activation signal 173 */ 174 public uint getActivateSignal() 175 { 176 return gtk_widget_class_get_activate_signal(gtkWidgetClass); 177 } 178 179 /** 180 * Gets the name used by this class for matching in CSS code. 181 * 182 * See [method@Gtk.WidgetClass.set_css_name] for details. 183 * 184 * Returns: the CSS name of the given class 185 */ 186 public string getCssName() 187 { 188 return Str.toString(gtk_widget_class_get_css_name(gtkWidgetClass)); 189 } 190 191 /** 192 * Retrieves the type of the [class@Gtk.LayoutManager] 193 * used by widgets of class @widget_class. 194 * 195 * See also: [method@Gtk.WidgetClass.set_layout_manager_type]. 196 * 197 * Returns: type of a `GtkLayoutManager` subclass, or %G_TYPE_INVALID 198 */ 199 public GType getLayoutManagerType() 200 { 201 return gtk_widget_class_get_layout_manager_type(gtkWidgetClass); 202 } 203 204 /** 205 * This should be called at class initialization time to specify 206 * actions to be added for all instances of this class. 207 * 208 * Actions installed by this function are stateless. The only state 209 * they have is whether they are enabled or not. 210 * 211 * Params: 212 * actionName = a prefixed action name, such as "clipboard.paste" 213 * parameterType = the parameter type 214 * activate = callback to use when the action is activated 215 */ 216 public void installAction(string actionName, string parameterType, GtkWidgetActionActivateFunc activate) 217 { 218 gtk_widget_class_install_action(gtkWidgetClass, Str.toStringz(actionName), Str.toStringz(parameterType), activate); 219 } 220 221 /** 222 * Installs an action called @action_name on @widget_class and 223 * binds its state to the value of the @property_name property. 224 * 225 * This function will perform a few santity checks on the property selected 226 * via @property_name. Namely, the property must exist, must be readable, 227 * writable and must not be construct-only. There are also restrictions 228 * on the type of the given property, it must be boolean, int, unsigned int, 229 * double or string. If any of these conditions are not met, a critical 230 * warning will be printed and no action will be added. 231 * 232 * The state type of the action matches the property type. 233 * 234 * If the property is boolean, the action will have no parameter and 235 * toggle the property value. Otherwise, the action will have a parameter 236 * of the same type as the property. 237 * 238 * Params: 239 * actionName = name of the action 240 * propertyName = name of the property in instances of @widget_class 241 * or any parent class. 242 */ 243 public void installPropertyAction(string actionName, string propertyName) 244 { 245 gtk_widget_class_install_property_action(gtkWidgetClass, Str.toStringz(actionName), Str.toStringz(propertyName)); 246 } 247 248 /** 249 * Returns details about the @index_-th action that has been 250 * installed for @widget_class during class initialization. 251 * 252 * See [method@Gtk.WidgetClass.install_action] for details on 253 * how to install actions. 254 * 255 * Note that this function will also return actions defined 256 * by parent classes. You can identify those by looking 257 * at @owner. 258 * 259 * Params: 260 * index = position of the action to query 261 * owner = return location for the type where the action was defined 262 * actionName = return location for the action name 263 * parameterType = return location for the parameter type 264 * propertyName = return location for the property name 265 * 266 * Returns: %TRUE if the action was found, %FALSE if @index_ 267 * is out of range 268 */ 269 public bool queryAction(uint index, out GType owner, out string actionName, out VariantType parameterType, out string propertyName) 270 { 271 char* outactionName = null; 272 GVariantType* outparameterType = null; 273 char* outpropertyName = null; 274 275 auto __p = gtk_widget_class_query_action(gtkWidgetClass, index, &owner, &outactionName, &outparameterType, &outpropertyName) != 0; 276 277 actionName = Str.toString(outactionName); 278 parameterType = new VariantType(outparameterType); 279 propertyName = Str.toString(outpropertyName); 280 281 return __p; 282 } 283 284 /** 285 * Sets the accessible role used by the given `GtkWidget` class. 286 * 287 * Different accessible roles have different states, and are 288 * rendered differently by assistive technologies. 289 * 290 * Params: 291 * accessibleRole = the `GtkAccessibleRole` used by the @widget_class 292 */ 293 public void setAccessibleRole(GtkAccessibleRole accessibleRole) 294 { 295 gtk_widget_class_set_accessible_role(gtkWidgetClass, accessibleRole); 296 } 297 298 /** 299 * Sets the `GtkWidgetClass.activate_signal` field with the 300 * given @signal_id. 301 * 302 * The signal will be emitted when calling [method@Gtk.Widget.activate]. 303 * 304 * The @signal_id must have been registered with `g_signal_new()` 305 * or g_signal_newv() before calling this function. 306 * 307 * Params: 308 * signalId = the id for the activate signal 309 */ 310 public void setActivateSignal(uint signalId) 311 { 312 gtk_widget_class_set_activate_signal(gtkWidgetClass, signalId); 313 } 314 315 /** 316 * Sets the `GtkWidgetClass.activate_signal` field with the signal id for 317 * the given @signal_name. 318 * 319 * The signal will be emitted when calling [method@Gtk.Widget.activate]. 320 * 321 * The @signal_name of @widget_type must have been registered with 322 * g_signal_new() or g_signal_newv() before calling this function. 323 * 324 * Params: 325 * signalName = the name of the activate signal of @widget_type 326 */ 327 public void setActivateSignalFromName(string signalName) 328 { 329 gtk_widget_class_set_activate_signal_from_name(gtkWidgetClass, Str.toStringz(signalName)); 330 } 331 332 /** 333 * Sets the name to be used for CSS matching of widgets. 334 * 335 * If this function is not called for a given class, the name 336 * set on the parent class is used. By default, `GtkWidget` 337 * uses the name "widget". 338 * 339 * Params: 340 * name = name to use 341 */ 342 public void setCssName(string name) 343 { 344 gtk_widget_class_set_css_name(gtkWidgetClass, Str.toStringz(name)); 345 } 346 347 /** 348 * Sets the type to be used for creating layout managers for 349 * widgets of @widget_class. 350 * 351 * The given @type must be a subtype of [class@Gtk.LayoutManager]. 352 * 353 * This function should only be called from class init functions 354 * of widgets. 355 * 356 * Params: 357 * type = The object type that implements the `GtkLayoutManager` 358 * for @widget_class 359 */ 360 public void setLayoutManagerType(GType type) 361 { 362 gtk_widget_class_set_layout_manager_type(gtkWidgetClass, type); 363 } 364 365 /** 366 * This should be called at class initialization time to specify 367 * the `GtkBuilder` XML to be used to extend a widget. 368 * 369 * For convenience, [method@Gtk.WidgetClass.set_template_from_resource] 370 * is also provided. 371 * 372 * Note that any class that installs templates must call 373 * [method@Gtk.Widget.init_template] in the widget’s instance initializer. 374 * 375 * Params: 376 * templateBytes = A `GBytes` holding the `GtkBuilder` XML 377 */ 378 public void setTemplate(Bytes templateBytes) 379 { 380 gtk_widget_class_set_template(gtkWidgetClass, (templateBytes is null) ? null : templateBytes.getBytesStruct()); 381 } 382 383 /** 384 * A convenience function that calls [method@Gtk.WidgetClass.set_template] 385 * with the contents of a `GResource`. 386 * 387 * Note that any class that installs templates must call 388 * [method@Gtk.Widget.init_template] in the widget’s instance 389 * initializer. 390 * 391 * Params: 392 * resourceName = The name of the resource to load the template from 393 */ 394 public void setTemplateFromResource(string resourceName) 395 { 396 gtk_widget_class_set_template_from_resource(gtkWidgetClass, Str.toStringz(resourceName)); 397 } 398 399 /** 400 * For use in language bindings, this will override the default 401 * `GtkBuilderScope` to be used when parsing GtkBuilder XML from 402 * this class’s template data. 403 * 404 * Note that this must be called from a composite widget classes class 405 * initializer after calling [method@GtkWidgetClass.set_template]. 406 * 407 * Params: 408 * scope_ = The `GtkBuilderScope` to use when loading 409 * the class template 410 */ 411 public void setTemplateScope(BuilderScopeIF scope_) 412 { 413 gtk_widget_class_set_template_scope(gtkWidgetClass, (scope_ is null) ? null : scope_.getBuilderScopeStruct()); 414 } 415 }